﻿/*!
* jQuery DivMenu plugin: 
* 
* version 0.1 2010-03-08
* Requires jQuery v1.3.2 or later
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Authors: Kim Seoung Min
*/
; (function($) {
    if (!$.KDBJQ) {
        $.KDBJQ = new Object();
    };

    $.KDBJQ.kcontextMenu = function(el, liname) {

        var base = this;
        // Access to jQuery and DOM versions of element
        base.$el = $(el);
        base.el = el;

        // Add a reverse reference to the DOM object
        base.$el.data("KDBJQ.contextMenu", base);

        base.init = function() {
            base.liname = liname;
            // Put your initialization code here
        };

        // Run initializer
        base.init();

        base.$el.bind("click", function(e) {
            // if (e.which == 3) {
            // alert('클릭');

            if ($(document.body).find('> .DivContextMenu').html() != null) {
                $(document.body).find('> .DivContextMenu').remove()
            }

            $(document.body).append("<div class='DivContextMenu'></div>");
            //  $(document.body).find('> .DivContextMenu').css("top", e.clientY)

            var menutop = e.clientY; //base.$el.offset().top + base.$el.outerHeight();
            var menuleft = e.clientX; // base.$el.offset().left;

            $(document.body).find('> .DivContextMenu').css("top", menutop);
            $(document.body).find('> .DivContextMenu').css("left", menuleft);
            //                    alert('offset_top : ' + base.$el.offset().top + ' - ' + base.$el.outerHeight());
            //                    alert('offsety : ' + base.$el.offset().left);
            base.$menu = $("#" + base.liname);
            $(document.body).find('> .DivContextMenu').append(base.$menu.html());
            $(document.body).find('> .DivContextMenu').bind("mouseleave", function(e) {
                $(document.body).find('> .DivContextMenu').remove()
            });

            //  }
            return false;
        });


        //        base.$el.bind("mouseover", function(e) {
        //            if ($(document.body).find('> .DivContextMenu').html() != null) {
        //                $(document.body).find('> .DivContextMenu').remove()
        //            }
        //            $(document.body).append("<div class='DivContextMenu'></div>");
        //            //  $(document.body).find('> .DivContextMenu').css("top", e.clientY)

        //            var menutop = base.$el.offset().top + base.$el.outerHeight();
        //            var menuleft = base.$el.offset().left;

        //            $(document.body).find('> .DivContextMenu').css("top", menutop);
        //            $(document.body).find('> .DivContextMenu').css("left", menuleft);
        //            //alert('offset_top : ' + base.$el.offset().top + ' - ' + base.$el.outerHeight());
        //            //alert('offsety : ' + base.$el.offsety);
        //            base.$menu = $("#" + base.liname);
        //            $(document.body).find('> .DivContextMenu').append(base.$menu.html());
        //            $(document.body).find('> .DivContextMenu').bind("mouseleave", function(e) {
        //                $(document.body).find('> .DivContextMenu').remove()
        //            });
        //        });

    };




    $.fn.kcontextMenu = function(liname) {
        return this.each(function() {
            (new $.KDBJQ.kcontextMenu(this, liname));
        });
    };


})(jQuery);